require(['config'], function () {
    require(['jquery'], function () {
        $('#footer').load('footer.html .footer');
        require(['jquery-cookie'], function () {
            function init() {
                this.$phone = $('.input-phone');
                this.$pass = $('.input-key');
                this.$btnreg = $('.btn-reg');
                this.$msgwrap = $('#msg-wrap');
                this.$autologin = $('.autologin');
                let autoflag = true;
                let _this = this;
                //php接口公共地址
                const phpurl = 'http://10.31.155.44/02/yiguo/php/';
                // const phpurl = ' http://10.31.155.44/02/git/fkc/yiguo/php/';


                // 提交事件

                this.$btnreg.on('click', function () {
                    let phone = _this.$phone.val();
                    let pass = _this.$pass.val();
                    let logindata = [phone, pass];
                    if (phone && pass) {
                        _this.$msgwrap.removeClass('msg-wrap');
                        $.ajax({
                            type: 'POST',
                            url: phpurl + 'login.php',
                            data: {
                                'phone': phone,
                                'pass': pass
                            }
                        }).done(function (data) {
                            if (data) {
                                if (autoflag) {
                                    $.cookie('logindata', logindata, { expires: 7 });
                                    $.cookie('loginname', phone, { expires: 7 });
                                } else {
                                    $.cookie('logindata', logindata,{ expires: -1});
                                    $.cookie('loginname', phone);
                                }
                                _this.$msgwrap.removeClass('msg-wrap');
                                window.location.href = `index.html`;
                            } else {
                                _this.$msgwrap.addClass('msg-wrap');
                                _this.$msgwrap.html(`<div class="msg-error">手机号或密码错误</div>`);
                            }
                        });
                    } else {
                        _this.$msgwrap.addClass('msg-wrap');
                        _this.$msgwrap.html(`<div class="msg-error">手机号或密码不能为空</div>`);
                    }
                });
                //自动登录
                this.autoin = function () {
                    //勾选自动登录
                    this.$autologin.on('click', function () {
                        if ($(this).prop('checked')) {
                            autoflag = true;
                        } else {
                            autoflag = false;
                        }
                        // console.log(autoflag);

                    });
                    //判断自动登录
                    let autodata = $.cookie('logindata');
                    if (autodata) {
                        autodata = autodata.split(',');
                        this.$phone.val(autodata[0]);
                        this.$pass.val(autodata[1]);
                        this.$autologin.attr({ checked: 'checked' });
                    }

                }
                this.autoin();




                // init结束
            }
            init();
        });
    });
});